@extends('admin.layout')
@section('ownCss')
    <link href="/admin/assets/css/loading.css" rel="stylesheet" type="text/css"/>
@stop
@section('content')
<div class="admin-biaogelist">
    <div class="listbiaoti am-cf">
      <ul class="am-icon-flag on">系统变量列表</ul>
      <dl class="am-icon-home" style="float: right;"> 当前位置： 首页 > <a href="javascript:void(0);">系统变量列表</a></dl>
    </div>

    <div class="am-form am-g">
          <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped" id="setting_table">
            <thead>
              <tr class="am-success">
                <th class="table-id">ID</th>
                <th class="table-title">描述</th>
                <th class="table-title">名称</th>
                <th class="table-title">值</th>
                <th width="163px" class="table-set">操作</th>
              </tr>
            </thead>
            <tbody>
            @foreach ($settings as $setting)
                <tr>
                    <td>{{($loop->index)+1}}</td>
                    <td>{{$setting->discription}}</td>
                    <td>{{$setting->name}}</td>
                    <td><input type="text" value="{{$setting->value or ''}}" id="setting{{$setting->id}}" style="border:none;" readonly></td>
                    <td>
                        @if($setting->name != 'PUB_USED_STORAGE')
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                    <button class="am-btn am-btn-default am-btn-xs am-text-secondary am-round modify_enable" data-id="{{$setting->id}}"  id="show_modify{{$setting->id}}">修改</button>
                                <button class="am-btn am-btn-default am-btn-xs am-text-secondary am-round modify_param" style="display: none" data-id="{{$setting->id}}"  id="modify{{$setting->id}}">提交</button>
                            </div>
                        </div>
                        @endif
                    </td>
                </tr>
            @endforeach
            </tbody>
          </table>
{{--        {!! $settings->render() !!}--}}
          <hr />
        </div>
</div>
@stop
@section('ownJs')
    <script src="/admin/assets/js/loading.js"></script>
    <script>
        $('.modify_enable').click(function(){
            var id = $(this).data('id') ;
            $('#setting'+id).removeAttr('readonly');
            $("#show_modify"+id).hide();
            $("#modify"+id).show();
        });
        $('#setting_table').on('click', '.modify_param', function(){
            var id = $(this).data('id') ;
            var value = $.trim($('#setting'+id).val());
            if(value == ''){
                $('#setting{{$setting->id}}').focus();
                alert("该变量不能为空");
                return false;
            }
            $.ajax({
                type: 'post',
                url: "/dashboard/setting/"+id,
                data:{value:value},
                dataType: 'json',
                async:false,
                success: function (result) {
                    if (result.code == 0) {
                        alert("修改成功");
                        $('#setting'+id).attr('readonly', 'true');
                        $("#show_modify"+id).show();
                        $("#modify"+id).hide();
                        location.href = location.href;
                    }else if(result.code == -1){
                        location.href = '/dashboard/login';
                    }else{
                        alert("修改失败!");
                    }
                },
                error:function(result){
                    console.log("修改失败");
                }
            });
        });

    </script>
@stop